package com.ruoyi.web.controller.admin;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.dto.XsOrderDto;
import com.ruoyi.system.domain.vo.order.XsOrderListVo;
import com.ruoyi.system.service.IXsOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单表Controller
 */
@RestController
@RequestMapping("/system/order")
public class XsOrderController extends BaseController {

    @Autowired
    private IXsOrderService xsOrderService;

    /**
     * 查询订单列表
     */
    @GetMapping("/list")
    public TableDataInfo appList(XsOrderDto orderDto) {
        startPage();
        return getDataTable(xsOrderService.selectOrderList(orderDto));
    }

    /**
     * 查询订单详情
     */
    @GetMapping("/orderDetails")
    public AjaxResult orderDetails(@RequestParam("orderId") String orderId)
    {
        return success(xsOrderService.orderDetails(orderId));
    }

    /**
     * 获得统计数据
     * @param orderDto
     * @return
     */
    @GetMapping("/getOrderStatistics")
    public AjaxResult getOrderStatistics(XsOrderDto orderDto)
    {
        return success(xsOrderService.getOrderStatistics(orderDto));
    }

    /**
     * 修改订单
     * @param xsOrderDto
     * @return
     */
    @PutMapping
    public AjaxResult edit(@RequestBody XsOrderDto xsOrderDto)
    {
        return toAjax(xsOrderService.updateBdmUser(xsOrderDto));
    }

    /**
     * 修改订单
     * @param xsOrderDto
     * @return
     */
    @PutMapping("/editNew")
    public AjaxResult editNew(@RequestBody XsOrderDto xsOrderDto)
    {
        return toAjax(xsOrderService.editNew(xsOrderDto));
    }


    /**
     * 修改订单是否刷单
     * @param xsOrderDto
     * @return
     */
    @PutMapping("/editBrushing")
    public AjaxResult editBrushing(@RequestBody XsOrderDto xsOrderDto) {
        return toAjax(xsOrderService.editBrushing(xsOrderDto));
    }

    /**
     * 新增
     * @param orderDto
     * @return
     */
    @PostMapping()
    public AjaxResult add(XsOrderDto orderDto) {
        return toAjax(xsOrderService.add(orderDto));
    }

    /**
     * 删除订单
     */
    @Log(title = "删除订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(xsOrderService.deleteXsOrderByIds(ids));
    }

    /**
     * 批量导入数据
     * @param file
     * @return
     */
    @Log(title = "批量导入数据", businessType = BusinessType.IMPORT)
    @PostMapping("/batchImportClue")
    public AjaxResult batchImportClue(MultipartFile file) {
        xsOrderService.batchImportDataClues(file);
        return success();
    }

    /**
     * 导出订单列表
     */
    @Log(title = "导出订单列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XsOrderDto orderDto)
    {
        List<XsOrderListVo> list = xsOrderService.selectOrderList(orderDto);
        ExcelUtil<XsOrderListVo> util = new ExcelUtil<XsOrderListVo>(XsOrderListVo.class);
        util.exportExcel(response, list, "订单列表");
    }

}